package com.summer.roman;

public abstract class Letter {
	
	protected int value;
	
	protected Letter leftLetter;
	protected Letter rightLetter;
	
	public abstract boolean allowedRepeat();
	
	public abstract boolean allowedReverse(Letter letter);
	
	public void setNextLetter(Letter nextLetter){
		
		if(nextLetter == null)
			return ;
		
		nextLetter.setNextLetter(leftLetter);
		if(allowedReverse(nextLetter))
			this.rightLetter = nextLetter;
		else
			this.leftLetter = nextLetter;
	}
	
	public int calculate() {
		int nextLetterValue = 0;
		if(leftLetter!=null)
			nextLetterValue = leftLetter.calculate();
		return value + nextLetterValue;
	}
	
}
